﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SignalR.Hubs;
using DAL;

/// <summary>
/// Summary description for Chat
/// </summary>

/// <todo>
/// fix adding discussion thread to db problem
/// enter to a discussion and get the thread from db [hard-coded from the webpage for now]
/// attachments - drag drop? now/latter?
/// </todo>
public class Discussion_handler : Hub
{
    public void Send(String msg, int discussionID, int memberID)
    {
        DateTime currentTime = System.DateTime.Now;
        String currentTimeText = currentTime.ToString();
        //String memberName;
        //using (var dbcontext = new iKonnectDevDBEntities())
        //{
        //    try
        //    {
        //    Member currentMemeber = dbcontext.Members.First(i => i.MemberID == memberID);
        //    memberName = currentMemeber.FullName;

 
        //    DiscussionThread newThread = new DiscussionThread()
        //    {
        //        DiscussionID = discussionID,
        //        MemberID = memberID,
        //        Timestamp = DateTime.Now,
        //        Text = msg,
        //        Attachment = null
        //    }; //we need to add attachments
        //    dbcontext.AddToDiscussionThreads(newThread);
            
        //        dbcontext.SaveChanges();
        //    }
        //    catch (Exception ee) { Clients.addMessage1(currentTimeText, ee.Message, "asd"); }// problem: it stucks here ><
        //}

        if (discussionID == 1)
        {
            Clients.addMessage1(currentTimeText, msg, "asds");
        }
        else if (discussionID == 2)
        {
            Clients.addMessage2(currentTimeText, msg, "asdas");
        }
    }


    public void Neww(String msg, int discussionID, int memberID)
    {
        DateTime currentTime = System.DateTime.Now;
        String currentTimeText = currentTime.ToString();
        Clients.addDiscussionThread(currentTimeText, msg, memberID);
    }
}